<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>任务管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function taskForm(taskId,taskGroupId){
			var url = "${ctx}/pro/projectTask/form?id="+taskId+"&taskGroup.id="+taskGroupId;
			top.$.jBox.open("iframe:"+url, "任务详情",810,$(top.document).height()-120,{
                buttons:{"提交":"ok", "关闭":true}, bottomText:"任务详情",submit:function(v, h, f){
                    var code;
                    if (v=="ok"){
                    	// 执行保存
                        //loading('正在提交，请稍等...');
                    	var flag = h.find("iframe")[0].contentWindow.submitForm();
                    	if(flag){
                    		location.reload();
                    	}
                        return false;
                    }
                }, loaded:function(h){
                    $(".jbox-content", top.document).css("overflow-y","hidden");
                }
            });
		}
		function taskFormDisable(taskId,taskGroupId){
			var url = "${ctx}/pro/projectTask/formDisable?id="+taskId+"&taskGroup.id="+taskGroupId;
			top.$.jBox.open("iframe:"+url, "任务详情",810,$(top.document).height()-120,{
                buttons:{"关闭":true}, bottomText:"任务详情",submit:function(v, h, f){
                    var code;
                    if (v=="ok"){
                    	// 执行保存
                        //loading('正在提交，请稍等...');
                    	h.find("iframe")[0].contentWindow.submitForm();
                    	location.reload();
                        return false;
                    }
                }, loaded:function(h){
                    $(".jbox-content", top.document).css("overflow-y","hidden");
                }
            });
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a id="btn" href="${ctx}/pro/projectTask/?taskGroup.id=${e.taskGroup.id}">任务列表</a></li>
		<shiro:hasPermission name="pro:projectTask:create"><li><a href="javascript:void(0);" onclick="taskForm('','${e.taskGroup.id}')">任务添加</a></li></shiro:hasPermission>
		<li><a href="${ctx}/pro/proLog/?task=task&project.id=${e.project.id}&taskGroup.id=${e.taskGroup.id}">项目日志</a></li>
		<li><a href="${ctx}/pro/project/ganttViewData?task=task&id=${e.project.id}&groupId=${e.taskGroup.id}">项目进度</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="projectTask" action="${ctx}/pro/projectTask/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="groupId" name="taskGroup.id" type="hidden" value="${e.taskGroup.id}"/>
		<a href="${ctx}/pro/project/">项目&gt;&gt;</a>
		<a id="btn" href="${ctx}/pro/taskGroup/list?project.id=${e.project.id}">&nbsp;任务组&gt;&gt;</a>
		<ul class="ul-form">
			<li><label>任务名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<%-- <li><label>任务组：</label>
				<form:select path="taskGroup.id" class="input-medium">
					<form:option value="" label=""/>
					<form:options items="${groups}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</li> --%>
			<li><label>负责人：</label>
				<sys:treeselect id="manager" name="manager.id" value="${projectTask.manager.id}" labelName="manager.name" labelValue="${projectTask.manager.name}"
					title="用户" url="/sys/office/treeData?type=3" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
			</li>
			<li><label>优先级：</label>
				<form:select path="priority" class="input-medium">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('task_priority')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>开始时间：</label>
				<input name="startTime" id="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
					value="<fmt:formatDate value="${projectTask.startTime}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,maxDate:'#F{$dp.$D(\'endTime\')}'});"/>
			</li>
			<li><label>结束时间：</label>
				<input name="endTime" id="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
					value="<fmt:formatDate value="${projectTask.endTime}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,minDate:'#F{$dp.$D(\'startTime\')}'});"/>
			</li>
			<li><label>任务状态：</label>
				<form:select path="status" class="input-medium">
   					<form:option value="" label=""/>
   					<form:option value="" label="未完成"/>
   					<form:options items="${fns:getDictList('task_status')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
   				</form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<c:set var="nowDate" value="<%=System.currentTimeMillis()%>"></c:set> 
		<thead>
			<tr>
				<th>任务名称</th>
				<th>负责人</th>
				<th>优先级</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>任务状态</th>
				<shiro:hasPermission name="pro:projectTask:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="projectTask">
			<tr>
				<td>
				<shiro:hasPermission name="pro:projectTask:edit">
					<a href="javascript:void(0);" onclick="taskForm('${projectTask.id}','${e.taskGroup.id}')">
						${projectTask.name}
					</a>
				</shiro:hasPermission>
				<shiro:lacksPermission name="pro:projectTask:edit">
					<a href="javascript:void(0);" onclick="taskFormDisable('${projectTask.id}','${e.taskGroup.id}')">
						${projectTask.name}
					</a>
				</shiro:lacksPermission>
				</td>
				<td>
					${projectTask.manager.name}
				</td>
				<td>
					${fns:getDictLabel(projectTask.priority, 'task_priority', '')}
				</td>
				<td>
					<fmt:formatDate value="${projectTask.startTime}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
					<fmt:formatDate value="${projectTask.endTime}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
					<c:if test="${not empty projectTask.endTime && projectTask.delFlag=='0'}">
						<c:choose>
							<c:when test="${nowDate-projectTask.endTime.time>0}">
								已超时
							</c:when>
							<c:otherwise>
								进行中
							</c:otherwise>
						</c:choose>
					</c:if>
					<c:if test="${projectTask.delFlag == '1'}">
						已归档
					</c:if>
				</td>
				<shiro:hasPermission name="pro:projectTask:edit"><td>
	    				<a href="${ctx}/pro/document/list?task.id=${projectTask.id}">查看文档</a>
					<c:if test="${fns:getUser().id == projectTask.manager && projectTask.delFlag == '0'}">
						<a href="${ctx}/pro/projectTask/delete?id=${projectTask.id}" onclick="return confirmx('确认要归档该任务吗？', this.href)">归档</a>
					</c:if>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>